## "China's Ideological Spectrum"
## by Jennifer Pan and Yiqing Xu

### Install Packages
## install.packages("plotrix")
## install.packages("mvtnorm")

rm(list=ls(all=TRUE))

################
## Figure 1
################

pdf("./graphs/toy1.pdf")
library(plotrix)
set.seed(1234)
par(mar=rep(0,4))
plot(1, type = "n", xlim = c(-2, 2), ylim = c(-2, 2),
     xlab = "", ylab = "", axes = F)
x <- rnorm(200) * 0.5
y <- rnorm(200) * 0.5
draw.circle(0, 0, 1, nv = 1000, border =4, col = NA, lty = 3, lwd = 2)
points(x,y, col = "gray30", pch = 1, cex = 1.5)
arrows(-1.5,0,1.5,0, code = 3, lwd = 5)
arrows(0, -1.5, 0,1.5, code = 3, lwd = 5)
lines(c(-1.55,1.55),c(-1.55,-1.55), lty = 3)
lines(c(-1.55,1.55),c(1.55,1.55), lty = 3)
lines(c(-1.55,-1.55),c(-1.55,1.55), lty = 3)
lines(c(1.55,1.55),c(-1.55,1.55), lty = 3)
text(1.8,1.8,"A", col = 4, cex = 3, font = 1)
text(-1.8,1.8,"B", col = 4, cex = 3, font = 1)
text(-1.8,-1.8,"C", col = 4, cex = 3, font = 1)
text(1.8,-1.8,"D", col = 4, cex = 3, font = 1)
text(-1.3,0.3,"Collectivism", col = 1, cex = 1.8, font = 1)
text(1.3,0.33,"Individualism", col = 1, cex = 1.8, font = 1)
text(0,-1.8,"Economic\nInterventionsim", col = 1, cex = 1.8, font = 1)
text(0,1.8,"Economic\nNon-interventionsim", col = 1, cex = 1.8, font = 1)
graphics.off()


pdf("./graphs/toy2.pdf")
library(mvtnorm)
set.seed(1234)
par(mar=rep(0,4))
plot(1, type = "n", xlim = c(-2, 2), ylim = c(-2, 2),
     xlab = "", ylab = "", axes = F)
x <- rmvnorm(200, sigma = matrix(c(1,0.995,0.995,1)*.22,2,2))
lines(c(-1.55,1.55),c(-1.55,1.55), col = 4, lwd = 2, lty =1)
points(x, col = "gray30", pch = 1, cex = 1.5)
arrows(-1.5,0,1.5,0, code = 3, lwd = 5)
arrows(0, -1.5, 0,1.5, code = 3, lwd = 5)
lines(c(-1.55,1.55),c(-1.55,-1.55), lty = 3)
lines(c(-1.55,1.55),c(1.55,1.55), lty = 3)
lines(c(-1.55,-1.55),c(-1.55,1.55), lty = 3)
lines(c(1.55,1.55),c(-1.55,1.55), lty = 3)
text(1.8,1.8,"A", col = 4, cex = 3, font = 1)
text(-1.8,1.8,"B", col = 4, cex = 3, font = 1)
text(-1.8,-1.8,"C", col = 4, cex = 3, font = 1)
text(1.8,-1.8,"D", col = 4, cex = 3, font = 1)
text(-1.3,0.3,"Collectivism", col = 1, cex = 1.8, font = 1)
text(1.3,0.3,"Individualism", col = 1, cex = 1.8, font = 1)
text(0,-1.8,"Economic\nInterventionsim", col = 1, cex = 1.8, font = 1)
text(0,1.8,"Economic\nNon-interventionsim", col = 1, cex = 1.8, font = 1)
graphics.off()


pdf("./graphs/toy3.pdf")
## ellipse
theta <- seq(0, 2 * pi, length=1000)
a <- 1.5; b <- 0.5; alpha = 0.8;
ex <- a * cos(theta) * cos(alpha) - b * sin(theta) * sin(alpha)
ey <- a * cos(theta) * sin(alpha) + b * sin(theta) * cos(alpha)
library(mvtnorm)
set.seed(1234)
par(mar=rep(0,4))
plot(1, type = "n", xlim = c(-2, 2), ylim = c(-2, 2),
     xlab = "", ylab = "", axes = F)
x <- rmvnorm(200, sigma = matrix(c(1,0.75,0.75,1)*.22,2,2))
lines(ex, ey, col = 4, lwd = 2, lty = 3)
points(x, col = "gray30", pch = 1, cex = 1.5)
arrows(-1.5,0,1.5,0, code = 3, lwd = 5)
arrows(0, -1.5, 0,1.5, code = 3, lwd = 5)
lines(c(-1.55,1.55),c(-1.55,-1.55), lty = 3)
lines(c(-1.55,1.55),c(1.55,1.55), lty = 3)
lines(c(-1.55,-1.55),c(-1.55,1.55), lty = 3)
lines(c(1.55,1.55),c(-1.55,1.55), lty = 3)
text(1.8,1.8,"A", col = 4, cex = 3, font = 1)
text(-1.8,1.8,"B", col = 4, cex = 3, font = 1)
text(-1.8,-1.8,"C", col = 4, cex = 3, font = 1)
text(1.8,-1.8,"D", col = 4, cex = 3, font = 1)
text(-1.3,0.3,"Collectivism", col = 1, cex = 1.8, font = 1)
text(1.3,0.3,"Individualism", col = 1, cex = 1.8, font = 1)
text(0,-1.8,"Economic\nInterventionsim", col = 1, cex = 1.8, font = 1)
text(0,1.8,"Economic\nNon-interventionsim", col = 1, cex = 1.8, font = 1)
graphics.off()



